<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    async function f1() {
      // ...
    }
    //实现一个async
    function fn(args) {
      return spawn(function* () {
        // ...
      });
    }
    function spawn(fun) {
      return new Promise((resolve, reject) => {
        const gen = fun();
        function step(nextF) {
          let next;
          try {
            next = nextF();
          } catch (e) {
            return reject(e);
          }
          if (next.done) {
            return resolve(next.value);
          }
          Promise.resolve(next.value).then(
            function (v) {
              step(function () {
                return gen.next(v);
              });
            },
            function (e) {
              step(function () {
                return gen.throw(e);
              });
            }
          );
        }
        step(function () {
          return gen.next(undefined);
        });
      });
    }
    class Foo {
      constructor() {
        console.log(1);
      }
    }

    class Bar extends Foo {
      constructor() {
        super();
        console.log(2);
      }
    }

    const bar = new Bar();
  </script>
</html>
